
/// @file Main entry point of the Execution Manager.
///
/// This is the main.c file containing the main function of the Adaptive Autosar Execution Manager.
//#include "execution_manager.h"
#include "redirect_process_output.h"
#include "logger.h"

#include "nosal/log/logging.h"

#include <cstring>

/// @brief Entry point for Execution Manager executable.
///
/// @param argc Standard main function parameter
/// @param argv Standard main function parameter
///
/// @note Execution Manager recognizes a command line option "NOSAL_ROOT". It can be used to specify
///       a base directory for where to search configuration files and Adaptive Applications.
/// @note Important program steps and errors are logged to the attached console.
/// @note Stdout and stderr are redirected to file /var/redirected/execution-manager
int main(int argc, char** argv)
{
    static const char kDefaultNosalRoot[] = "/";
    static const char kNosalRootName[] = "NOSAL_ROOT=";

    const char* nosal_root = kDefaultNosalRoot;

    // Parse command line arguments, skip the first (0, executable path)
    for (std::int32_t arg_idx = 1; arg_idx < argc; ++arg_idx) {
        if (::strstr(argv[arg_idx], kNosalRootName) != nullptr) {
            nosal_root = argv[arg_idx] + ::strlen(kNosalRootName);
        }
    }

    netaos::nosal::log::InitLogging(
        "EXEC", "Execution Management", netaos::nosal::exec::internal::kLogLevel, netaos::nosal::exec::internal::kLogMode);

    // Redirect terminal output of execution manager to /var/redirected/<kOutputDirName>
    static const char kOutputDirName[] = "execution_manager";
    netaos::nosal::exec::internal::RedirectProcessOutput(kOutputDirName);

    // Execution Manager can either power off the system or exit normally.
 //   return netaos::nosal::exec::internal::ExecutionManager::Run(nosal_root);
}
